package com.mall.dubbo.api;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.SmsHomeBrandMapper;
import com.mall.model.domain.SmsHomeBrand;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author xyiaao
 * @description 针对表【sms_home_brand(首页推荐品牌表)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
public class SmsHomeBrandApiImpl extends ServiceImpl<SmsHomeBrandMapper, SmsHomeBrand>
        implements SmsHomeBrandApi {

    @Autowired
    private SmsHomeBrandMapper smsHomeBrandMapper;

    //分页查询推荐品牌
    public Page<SmsHomeBrand> listPage(Integer pageNum, Integer pageSize, String brandName, Integer recommendStatus) {

        LambdaQueryWrapper<SmsHomeBrand> lqw = new LambdaQueryWrapper<>();
        lqw.like(StringUtils.isNotEmpty(brandName), SmsHomeBrand::getBrandName, brandName);
        lqw.eq(recommendStatus != null, SmsHomeBrand::getRecommendStatus, recommendStatus);
        lqw.orderByDesc(SmsHomeBrand::getSort);
        Page<SmsHomeBrand> page = new Page<>(pageNum, pageSize);

        return smsHomeBrandMapper.selectPage(page, lqw);
    }

    //批量修改推荐品牌状态
    public void updateBYIds(List<Long> ids, SmsHomeBrand smsHomeBrand) {

        LambdaQueryWrapper<SmsHomeBrand> lqw = new LambdaQueryWrapper<>();
        lqw.in(CollUtil.isNotEmpty(ids), SmsHomeBrand::getId, ids);
        smsHomeBrandMapper.update(smsHomeBrand, lqw);
    }

    //修改推荐品牌排序
    public void updateSort(Integer id, SmsHomeBrand homeBrand) {

        LambdaQueryWrapper<SmsHomeBrand> lqw = new LambdaQueryWrapper<>();
        lqw.eq(id != null, SmsHomeBrand::getId, id);
        smsHomeBrandMapper.update(homeBrand, lqw);
    }

    @Override
    public List<SmsHomeBrand> findByIds(List<Long> ids, SmsHomeBrand smsHomeBrand) {

        LambdaQueryWrapper<SmsHomeBrand> lqw = new LambdaQueryWrapper<>();
        lqw.in(CollUtil.isNotEmpty(ids), SmsHomeBrand::getId, ids);
        lqw.eq(SmsHomeBrand::getRecommendStatus, smsHomeBrand.getRecommendStatus());

        return smsHomeBrandMapper.selectList(lqw);
    }

}




